#!/usr/bin/perl

package MyPackage;

use strict;
use warnings;
use base qw(Net::Server::PreFork); # any personality will do

MyPackage->run;

### over-ridden subs below
sub default_values {
    return {
	conf_file => '/home/jmrenouard/my_server.conf',
    }
}

register_sig(PIPE => 'IGNORE',
               HUP  => 'DEFAULT',
               USR1 => sub { print "I got a SIG $_[0]\n"; },
               USR2 => sub { print "I got a SIG $_[0]\n"; },
               CHLD => sub {print "I got a SIG $_[0]\n";  die "KILL ME !\n"; },
	       TERM => sub { print "I got a SIG $_[0]\n"; die "KILL ME !\n"; },
	       );
	       
sub process_request {
    my $self = shift;
    eval {

	local $SIG{'ALRM'} = sub { die "Timed Out!\n" };
	my $timeout = 15; # give the user 3 seconds to type some lines

	my $previous_alarm = alarm($timeout);
	&check_sigs();
	while (<STDIN>) {
	    s/\r?\n$//;
	    print "You said '$_'\r\n";
	    alarm($timeout);
	    &check_sigs();
	}
	alarm($previous_alarm);
    };

    if ($@ =~ /timed out/i) {
	print STDOUT "Timed Out.\r\n";
	return;
    }

}
1;
